<template>
	<view>
		<view class="box">
			<uni-datetime-picker style="width: 40%;float: right; padding: 30rpx 30rpx 0 0;" type="date"
				v-model="single" @change="change" />
		</view>
		<uni-card v-for="(item,index) in barChartList" :key="index">
			<uni-section :title="item.className" type="line"></uni-section>
			<qiun-data-charts type="column" :opts="opts" @getIndex="tap($event,item)" :chartData="item.chartData" />
		</uni-card>
	</view>
</template>

<script>
	import teacherClass from "@/api/modules/teachClass.js"
	import {
		parseTime
	} from "@/utils/date.js"
	export default {
		data() {
			return {
				single: "",
				barChartList: [],
				bzrUrl: "/pages/index/index",
				topName: "班级考勤",
				userName: "",
				chartData: {
					categories: ["上午", "中午", "晚上"],
					series: [{
							name: "迟到",
							data: [35, 36, 31]
						},
						{
							name: "请假",
							data: [18, 27, 21]
						},
						{
							name: "正常打卡",
							data: [18, 27, 21]
						}
					]
				},
				opts: {
					// color: ["#EE6666", "#73C0DE", "#3CA272"],
					color: ["#578f53", "#b94a3e", "#fa8e44"],
					padding: [15, 15, 0, 5],
					enableScroll: false,
					legend: {},
					xAxis: {
						disableGrid: true
					},
					yAxis: {
						disabled: true,
						data: [{
							min: 0
						}]
					},
					extra: {
						column: {
							type: "group",
							width: 10,
							activeBgColor: "#000000",
							activeBgOpacity: 0.08
						}
					}
				}
			}
		},
		methods: {
			tap(e, item) {
				if (e.currentIndex.index == -1) {
					return
				}
				let time = ""
				item.chartData.categories.forEach((value, index) => {
					if (e.currentIndex.index == index) {
						time = value
					}
				})
				uni.navigateTo({
					url: `/pages_duty/classTeacher/classAttend/attendDetail?chartData=${JSON.stringify(item.chartData)}&className=${item.className}&classId=${item.classId}&time=${time}&single=${this.single}`
				})
			},
			getAllClassAttendanceByClsTeachId() {
				teacherClass.getAllClassAttendanceByClsTeachId({
					"clsTeacherId": uni.getStorageSync("loginId"),
					"assessDate": this.upDateTime
				}).then(res => {
					this.barChartList = res.data
				})
			},
			change(e) {
				this.single = e
				if (e) {
					teacherClass.getAllClassAttendanceByClsTeachId({
						"clsTeacherId": uni.getStorageSync("loginId"),
						"assessDate": e
					}).then(res => {
						this.barChartList = res.data
					})
				}
			}
		},
		onLoad(options) {
			this.upDateTime = parseTime(Date.now()).slice(0, 10)
			this.single = parseTime(Date.now()).slice(0, 10)
			this.userName = uni.getStorageSync("userName")
			this.getAllClassAttendanceByClsTeachId()
			console.log(this.upDateTime)
		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.indexContent {
		height: 100vh;
	}

	.charts-box {
		width: 90%;
		height: 500rpx;
		margin: 10rpx auto;
	}

	/deep/.uni-section .uni-section-header__decoration[data-v-f7ca1098] {
		background-color: #90d1cb;
	}

	/deep/.uni-section .uni-section-header__content[data-v-f7ca1098] {
		margin-left: 20rpx;
	}

	.box::after {
		display: block;
		clear: both;
		content: "";
	}
</style>